//  @ Project : GagalPanen
//  @ File Name : plantablecell.cpp
//  @ Date : 3/9/2011
//  @ Author : 
//
//

#include <assert.h>
#include "plantablecell.hpp"
#include "creatures.hpp"

PlantableCell::PlantableCell(GameInterface* game) :
    Cell(game),
    is_plowed_(false), is_watered_(false), is_burning_(false) {
}

PlantableCell::PlantableCell(GameInterface* game, std::ifstream& is) :
    Cell(game, is),
    is_plowed_(false), is_watered_(false), is_burning_(false) {
  is >> is_plowed_ >> is_watered_ >> is_burning_;
}

void PlantableCell::save(std::ofstream& os) {
  Cell::save(os);
  os << (int)isPlowed() << " " << (int)isWatered() << " " <<
          (int)isBurning() << std::endl;
}

PlantableCell::~PlantableCell() {
}

void PlantableCell::advanceDay() {
  is_watered_ = false;
  return;
}

void PlantableCell::advanceTime() {
  return;
}

bool PlantableCell::isEnterable() {
  return true;
}

bool PlantableCell::isPlantable() {
  return true;
}

bool PlantableCell::isPlanted() { 
  return game_->getCreatures()->getPlants()->containsPlantAt(this);
}

bool PlantableCell::isPlowed() {
  return is_plowed_;
}

bool PlantableCell::isSteppable() {
  return !game_->getCreatures()->containsUnsteppableCreatureAt(this) && !isBurning();
}

bool PlantableCell::isWatered() {
  return is_watered_;
}

bool PlantableCell::isBurning() {
  return is_burning_;
}

void PlantableCell::plow() {
  is_plowed_ = true;
  //TODO
  //harus dikasi buat ngilangin plant
}

void PlantableCell::unplow() {
  is_plowed_ = false;
}

void PlantableCell::water() {
  if (is_burning_) {
    is_burning_ = false;
    return;
  }
  is_watered_ = true;
}

void PlantableCell::burn() {
  is_burning_ = true;
  is_watered_ = false;
}

void PlantableCell::removePlant(){
 assert(game_->getCreatures()->getPlants()->containsPlantAt(this));
 game_->getCreatures()->getPlants()->removePlant(
    game_->getCreatures()->getPlants()->getPlantAt(this));
 return;   
}
